package com.ruoyi.web.controller.fantasy;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyUser;
import com.ruoyi.fantasy.service.IFantasyUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * fantasy用户 信息操作处理
 * 
 * @author wanghui
 * @date 2019-07-05
 */
@Controller
@RequestMapping("/fantasy/fantasyUser")
public class FantasyUserController extends BaseController
{
    private String prefix = "fantasy/fantasyUser";
	
	@Autowired
	private IFantasyUserService fantasyUserService;
	
	@RequiresPermissions("fantasy:fantasyUser:view")
	@GetMapping()
	public String fantasyUser()
	{
	    return prefix + "/fantasyUser";
	}
	
	/**
	 * 查询fantasy用户列表
	 */
	@RequiresPermissions("fantasy:fantasyUser:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FantasyUser fantasyUser)
	{
		startPage();
        List<FantasyUser> list = fantasyUserService.selectFantasyUserList(fantasyUser);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出fantasy用户列表
	 */
	@RequiresPermissions("fantasy:fantasyUser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyUser fantasyUser)
    {
    	List<FantasyUser> list = fantasyUserService.selectFantasyUserList(fantasyUser);
        ExcelUtil<FantasyUser> util = new ExcelUtil<FantasyUser>(FantasyUser.class);
        return util.exportExcel(list, "fantasyUser");
    }
	
	/**
	 * 新增fantasy用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存fantasy用户
	 */
	@RequiresPermissions("fantasy:fantasyUser:add")
	@Log(title = "fantasy用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FantasyUser fantasyUser)
	{		
		return toAjax(fantasyUserService.insertFantasyUser(fantasyUser));
	}

	/**
	 * 修改fantasy用户
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		FantasyUser fantasyUser = fantasyUserService.selectFantasyUserById(id);
		mmap.put("fantasyUser", fantasyUser);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存fantasy用户
	 */
	@RequiresPermissions("fantasy:fantasyUser:edit")
	@Log(title = "fantasy用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FantasyUser fantasyUser)
	{		
		return toAjax(fantasyUserService.updateFantasyUser(fantasyUser));
	}
	
	/**
	 * 删除fantasy用户
	 */
	@RequiresPermissions("fantasy:fantasyUser:remove")
	@Log(title = "fantasy用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(fantasyUserService.deleteFantasyUserByIds(ids));
	}
	
}
